package com.xinqi.modules.course.clazz.controller.app;

import com.xinqi.common.base.current.Current;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.Param;
import com.xinqi.common.base.response.R;
import com.xinqi.common.base.user.Account;
import com.xinqi.modules.course.clazz.dto.req.ClassOperationLogCreateDTO;
import com.xinqi.modules.course.clazz.dto.req.ClassOperationLogQueryDTO;
import com.xinqi.modules.course.clazz.dto.req.ClassOperationLogUpdateDTO;
import com.xinqi.modules.course.clazz.dto.rsp.ClassOperationLogResultDTO;
import com.xinqi.modules.course.clazz.service.ClassOperationLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 班级日志控制层
 *
 * @author: system
 * @date: 2023/01/17
 */
@Tag(name = "App-班级日志", description = "班级日志")
@RestController
@RequestMapping("/app/class-operation-log")
@RequiredArgsConstructor
public class ClassOperationLogAppController {
    private final ClassOperationLogService classOperationLogService;

    @Operation(summary = "班级日志-分页")
    @GetMapping("/page")
    public R<PageInfo<ClassOperationLogResultDTO>> page(Param pageable, ClassOperationLogQueryDTO dto) {
        PageInfo<ClassOperationLogResultDTO> page = classOperationLogService.page(pageable, dto);
        return R.data(page);
    }

    @Operation(summary = "班级日志-详情")
    @GetMapping("/{id}")
    public R<ClassOperationLogResultDTO> findById(@PathVariable("id") Long id) {
        ClassOperationLogResultDTO dto = classOperationLogService.findById(id);
        return R.data(dto);
    }

    @Operation(summary = "新增班级日志")
    @PostMapping
    public R<Long> insert(@Current Account account, @Validated @RequestBody ClassOperationLogCreateDTO dto) {
        return R.data(classOperationLogService.insert(dto));
    }

    @Operation(summary = "修改班级日志")
    @PutMapping("/{id}")
    public R<Boolean> update(@Current Account account, @PathVariable("id") Long id, @Validated @RequestBody ClassOperationLogUpdateDTO dto) {
        dto.setId(id);
        return R.data(classOperationLogService.updateById(dto));
    }

    @Operation(summary = "删除班级日志")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@Current Account account, @PathVariable("id") Long id) {
        return R.data(classOperationLogService.deleteById(id));
    }

}
